//
//  OtherLoginsViewController.m
//  Snigger
//
//  Created by Young on 16/8/18.
//  Copyright © 2016年 Smile. All rights reserved.
//

#import "OtherLoginsViewController.h"

#import "POP.h"

#define kSpringFactor 10.0f

#define kX(rect) CGRectGetMinX(rect)
#define kY(rect) (CGRectGetMinY(rect))
#define kHeight (self.view.bounds.size.height / 2.0)
#define kWidth (self.view.bounds.size.width / 2.0 - 35)

@interface OtherLoginsViewController ()

@property (weak, nonatomic) IBOutlet UILabel *noticeLabel;
@property (weak, nonatomic) IBOutlet UIButton *qqLoginButton;
@property (weak, nonatomic) IBOutlet UIButton *twitterLoginButton;
@property (weak, nonatomic) IBOutlet UIButton *wechatLoginButton;

@end

@implementation OtherLoginsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.view.backgroundColor = [UIColor grayColor];
    self.navigationController.navigationBar.hidden = NO;
    
    // 添加POP动画
    [self addPOPSpringAnimation];
    
    
}

#pragma mark - 添加POP动画
- (void)addPOPSpringAnimation {
    POPSpringAnimation *springAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPViewFrame];
    springAnimation.springBounciness = kSpringFactor * 2;
    springAnimation.springSpeed = kSpringFactor / 10;
    springAnimation.fromValue = [NSValue valueWithCGRect:CGRectMake(kX(_noticeLabel.bounds), kY(_noticeLabel.bounds), _noticeLabel.bounds.size.width, _noticeLabel.bounds.size.height)];
    springAnimation.toValue = [NSValue valueWithCGRect:CGRectMake(kX(_noticeLabel.bounds) + 26, kY(_noticeLabel.bounds) + 139, _noticeLabel.bounds.size.width, _noticeLabel.bounds.size.height)];
    springAnimation.beginTime = CACurrentMediaTime();
    __weak typeof(self) weakSelf = self;
    springAnimation.completionBlock = ^void(POPAnimation *anim, BOOL finished){
        NSLog(@"Animation end.");
        weakSelf.view.userInteractionEnabled = YES;
    };
    [_noticeLabel pop_addAnimation:springAnimation forKey:nil];
    
    __weak POPSpringAnimation *animation = [POPSpringAnimation animationWithPropertyNamed:kPOPViewFrame];
    animation.springBounciness = kSpringFactor * 2;
    animation.springSpeed = kSpringFactor / 10;
    animation.fromValue = [NSValue valueWithCGRect:CGRectMake(kWidth, kHeight, _qqLoginButton.bounds.size.width, _qqLoginButton.bounds.size.height)];
    animation.toValue = [NSValue valueWithCGRect:CGRectMake(kWidth / 5.0, kHeight - 80, _qqLoginButton.bounds.size.width, _qqLoginButton.bounds.size.height)];
    animation.beginTime = CACurrentMediaTime();
    animation.completionBlock = ^(POPAnimation *a, BOOL f) {
        
    };
    [_qqLoginButton pop_addAnimation:animation forKey:nil];
    
    POPSpringAnimation *twitterAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPViewFrame];
    twitterAnimation.springBounciness = kSpringFactor * 2;
    twitterAnimation.springSpeed = kSpringFactor / 10;
    twitterAnimation.fromValue = [NSValue valueWithCGRect:CGRectMake(kWidth, kHeight + 10, _twitterLoginButton.bounds.size.width, _twitterLoginButton.bounds.size.height)];
    twitterAnimation.toValue = [NSValue valueWithCGRect:CGRectMake(kWidth / 1.5 + 32, kHeight, _twitterLoginButton.bounds.size.width, _twitterLoginButton.bounds.size.height)];
    twitterAnimation.beginTime = CACurrentMediaTime();
    twitterAnimation.completionBlock = ^(POPAnimation *a, BOOL f) {
        
    };
    [_twitterLoginButton pop_addAnimation:twitterAnimation forKey:nil];
    
    POPSpringAnimation *wechatAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPViewFrame];
    wechatAnimation.springBounciness = kSpringFactor * 2;
    wechatAnimation.springSpeed = kSpringFactor / 10;
    wechatAnimation.fromValue = [NSValue valueWithCGRect:CGRectMake(kWidth, kHeight, _wechatLoginButton.bounds.size.width, _wechatLoginButton.bounds.size.height)];
    wechatAnimation.toValue = [NSValue valueWithCGRect:CGRectMake(kWidth / 2.0 - 90, CGRectGetMinY(_wechatLoginButton.frame) + kHeight / 2.0, _wechatLoginButton.bounds.size.width, _wechatLoginButton.bounds.size.height)];
    wechatAnimation.beginTime = CACurrentMediaTime();
    wechatAnimation.completionBlock = ^(POPAnimation *a, BOOL f) {
        
    };
    [_wechatLoginButton pop_addAnimation:wechatAnimation forKey:nil];
}

- (IBAction)wechatClicked:(UIButton *)sender {

}

- (IBAction)twitterClicked:(UIButton *)sender {

}

- (IBAction)qqClicked:(UIButton *)sender {

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
